package com.team.cloudsharing.controller.mail;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.team.cloudsharing.dto.Message;
import com.team.cloudsharing.service.mail.MailService;

@RestController
@RequestMapping("/mail")
public class MailControllerImpl implements MailController{
	
	final static Logger logger = Logger.getLogger(MailControllerImpl.class);

	@Autowired
	MailService mailService;
	
	@Override
	@RequestMapping(value = "/sendMailActivateAccount", method = RequestMethod.GET)
	public void sendMailActivateAccount(@RequestParam("userEmail") String userEmail) {
		logger.info("GET /mail/sendMailActivateAccount - userEmail: " + userEmail);
		mailService.sendMailActivateAccount(userEmail);
	}

	@Override
	@RequestMapping(value = "/sendMailForgotPassword", method = RequestMethod.GET)
	public void sendMailForgotPassword(@RequestParam("userEmail") String userEmail) {
		logger.info("GET /mail/sendMailForgotPassword - userEmail: " + userEmail);
		mailService.sendMailForgotPassword(userEmail);
	}

	@Override
	@RequestMapping(value = "/sendMailShareFolder/{folderId}", method = RequestMethod.GET)
	public void sendMailShareFolder(@RequestParam("userEmail")String userEmailReceive, @PathVariable("folderId") long folderId, @RequestParam("userEmailShared") String userEmailShare) {
		logger.info("GET /mail/sendMailShareFolder - userEmail: " + userEmailReceive + " - folderId: " + folderId + " - userEmailShared" + userEmailShare);
		mailService.sendMailShareFolder(userEmailReceive, folderId, userEmailShare);
	}


	@Override
	@RequestMapping(value = "/sendMailShareLink", method = RequestMethod.GET)
	public ResponseEntity<Message> sendLinkToEmail(@RequestParam("userEmail")String userEmail, @RequestParam("documentUrl")String documentUrl, @RequestParam("userEmailShare")String userEmailShare){
		logger.info("GET /mail/sendMailShareLink - userEmail: " + userEmail);
		mailService.sendLinkToEmail(userEmail, documentUrl, userEmailShare);
		return new ResponseEntity<Message>(new Message("Success"), HttpStatus.OK);
	}
}
